﻿using System;
using System.Text;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Pages_CommonPages_Home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        if (!IsPostBack)
        {
            GetTop2Competition();
            GetCompetitionTop();
            GetTop8Design();
            GetCompetitions();
            GetAwards();
        }
    }
    private void GetCompetitionTop()
    {
        CommonBUS com = new CommonBUS();
        Competition c = new Competition();
        c = com.getCompetitionUpcomming();
        imgCompeTop.ImageUrl = "~/Images/Competition/" + c.CompImage;
        DateTime da = new DateTime();
        da = Convert.ToDateTime(c.StartDate);
        DateTime de = new DateTime();
        de = Convert.ToDateTime(c.EndDate);
        lblDate.Text = da.ToString("MM/dd/yyyy");
        lblEndDate.Text = de.ToString("MM/dd/yyyy");
        lblName.Text = c.Name;
        txtDescription.Text = Filter(c.Description);
        linkdetailCompetition.NavigateUrl = "DetailCompetion.aspx?CID=" + c.ComId;
    }

    private void GetTop2Competition()
    {
        CommonBUS com = new CommonBUS();
        Competition c = new Competition();
        c = com.getTop2Competition();
        imgCompeBottom.ImageUrl = "~/Images/Competition/" + c.CompImage;
        DateTime da = new DateTime();
        da = Convert.ToDateTime(c.StartDate);
        DateTime de = new DateTime();
        de = Convert.ToDateTime(c.EndDate);
        lblDateBottom.Text = da.ToString("MM/dd/yyyy");
        lblEndDateBottom.Text = de.ToString("MM/dd/yyyy");
        lblNameBottom.Text = c.Name;
        txtDescriptionBottom.Text = Filter(c.Description);
        linkDetailCompetitionBottom.NavigateUrl = "DetailCompetion.aspx?CID=" + c.ComId;
    }

    private void GetTop8Design()
    {
        CommonBUS com = new CommonBUS();
        dtListDesign.DataSource = com.GetTop8Design();
        dtListDesign.DataBind();
    }

    private void GetAwards()
    {
        CommonBUS com = new CommonBUS();
        //Competition c = new Competition();
        DataSet ds = com.GetOneAwards();
        lblNameAward.Text = ds.Tables[0].Rows[0]["name"].ToString();
        dtaListAwards.DataSource = ds;
        dtaListAwards.DataBind();
    }

    private void GetCompetitions()
    {
        CommonBUS com = new CommonBUS();
        Competition c = new Competition();
        dtListCompetitions.DataSource = com.getCompetitions();
        dtListCompetitions.DataBind();
    }



    public static string Filter(string _txt)
    {
        try
        {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Insert(0, _txt);
            if (strBuilder.Length > 50)
            {
                return strBuilder.ToString().Substring(0, 100) + "...";
            }
            else
            {
                return strBuilder.ToString();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    
}